package com.zhuiyun.educations.api.coursefile.controller;

import com.zhuiyun.educations.api.coursefile.entity.CourseFile;
import com.zhuiyun.educations.api.coursefile.service.CourseFileService;
import com.zhuiyun.educations.api.uploadFile.entity.FileManage;
import com.zhuiyun.educations.api.uploadFile.service.FileManageService;
import com.zhuiyun.educations.common.errorCode.CommonException;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


/**
 * @ClassName CourseFileController
 * @Description TODO
 * @Author ys
 * @Date 2023/6/23 16:03
 **/
@Slf4j
@CrossOrigin
@RestController
@Api(tags = "课程资料")
@RequestMapping("/coursefile")
public class CourseFileController {
    @Resource
    CourseFileService courseFileService;
    @Resource
    FileManageService fileManageService;
    /**
     * @Author ys
     * @Description TODO 分页查询
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param pageRequest
     */
    @GetMapping("/getCourseFile")
    @ApiOperation(value = "课程资料的分页查询方法")
    public CommonResult getCourseFile(PageRequest pageRequest) {
        return courseFileService.getCourseFile(pageRequest);
    }
    /**
     * @Author ys
     * @Description TODO 新增
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param courseFile
     */
    @PostMapping("/addCourseFile")
    @ApiOperation(value = "课程资料的添加方法")
    public CommonResult addCourseFile(CourseFile courseFile, MultipartFile file, String projectName) throws CommonException {
        FileManage fileManage1 = fileManageService.saveFileToSystem(file, projectName);
        System.out.println("11111111111111"+fileManage1);
        courseFile.setFileId(fileManage1.getId());
        return courseFileService.addCourseFile(courseFile,file,projectName);
    }
    /**
     * @Author ys
     * @Description TODO 修改
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param courseFile
     */
    @PutMapping("/updateCourseFile")
    @ApiOperation(value = "课程价钱的修改方法")
    public CommonResult updateCourseFile(@RequestBody CourseFile courseFile) {
        log.info("修改");
        return courseFileService.updateCourseFile(courseFile);
    }
    /**
     * @Author ys
     * @Description TODO 章节下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @GetMapping("/fileSelect")
    @ApiOperation(value = "课程资料的资料动态下拉方法")
    public CommonResult fileSelect(){
        log.info("资料动态下拉");
        return courseFileService.fileSelect();
    }
    /**
     * @Author ys
     * @Description TODO 逻辑删除
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @DeleteMapping("deleteCourseFileById")
    @ApiOperation(value = "课程资料的逻辑删除方法")
    public CommonResult deleteCourseFileById(int id) {
        return courseFileService.deleteCourseFileById(id);
    }
}
